import request from '../../utils/request';
export default () => {
   // https://pipeline.ebonex.io/api/cms/publish/chunk/108
   return {
     name:'vite-plugin-cms-html',
      transformIndexHtml:{
       order:'pre',
       handler:async  function(){
        const res= await  request('https://pipeline.ebonex.io/api/cms/publish/chunk/108');
        const chunk= res.data.filter((item:any)=>{
           return item.env===1;
         });
         //https://global-static.ebonex.io/multi/saas/Index_1714034706977.cms
         const cms= await  request(chunk?.[0]?.fileUrl,{
          type:'text'
         });
         const result= cms.replace(/<script\s+type="module"\s+crossorigin\s+src="(.*)">?/g,()=>{
          return  `<script  type="module" crossorigin src="/src/main.tsx">`;
         });
         console.log("cms",result);
         return result;
       }
      }
   };
};